package com.example.administrator.yuejian_2.activity;

<<<<<<< HEAD
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.adapter.MyPostAdapter;
import com.example.administrator.yuejian_2.bean.MyPostBean;
import com.example.administrator.yuejian_2.interservice.Const;
import com.example.administrator.yuejian_2.interservice.UserService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MyPostActivity extends AppCompatActivity {
    private ImageButton back;
    private RecyclerView recyclerView;
    private MyPostAdapter adapter;
    private Context context;
    private int uid;
=======
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.administrator.yuejian_2.R;

public class MyPostActivity extends AppCompatActivity {
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
<<<<<<< HEAD
        setContentView(R.layout.activity_mypost);

        uid = getIntent().getIntExtra("uid",0);
        recyclerView = (RecyclerView) findViewById(R.id.mypost_recyclerView);
        mypost();

        back = (ImageButton) findViewById(R.id.mypost_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void mypost(){
        context = MyPostActivity.this;
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        UserService service = retrofit.create(UserService.class);
        Call<List<MyPostBean>> call = service.mypost(uid);
        call.enqueue(new Callback<List<MyPostBean>>() {
            @Override
            public void onResponse(Call<List<MyPostBean>> call, Response<List<MyPostBean>> response) {
                if (response.body() != null){
                    adapter = new MyPostAdapter(context,response.body());
                    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());

                }
            }

            @Override
            public void onFailure(Call<List<MyPostBean>> call, Throwable t) {

            }
        });
=======
        setContentView(R.layout.activity_my_post);
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
    }
}
